﻿@if (false) {<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.min.js" type="text/javascript" />}
@{string list = "list8", pager = "pager8", entity = "Configuration";}
<table id="@list" class="scroll" cellpadding="0" cellspacing="0">
</table>
<div id="@pager" class="scroll" style="text-align: center;">
</div>

<script type="text/javascript">
    jQuery(function () {
        $("#@list").jqGrid({
            url: "/@entity/index/",
            colNames: ["配置单名称", "物料名称", "物料编号", "物料名称", "备注"],
            colModel: [
            $.jgridx.strCol("Name"),
            $.jgridx.customAutoCol("ProductId", "/configuration/get", "/product/get?id="),
            $.extend($.jgridx.strCol("Product.Number"), { editable : false }),
            $.extend($.jgridx.strCol("Product.Name"), { editable : false }),
            {
                name: "Remark",
                index: "Remark",
                width: 280,
                editable: true,
                edittype: "textarea",
                search: false
            }
            ],

            pager: $('#@pager'),
            sortname: "@(entity)Id",
            sortorder: "desc",
            subGrid: true,

            subGridRowExpanded: function (subgrid_id, row_id) {
            @{string childentity = "ConfigurationItem";}
                var subgrid_table_id,
                pager_id;
                subgrid_table_id = subgrid_id + "_t";
                pager_id = "p_" + subgrid_table_id;
                $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + pager_id + "' class='scroll'></div>");
                jQuery("#" + subgrid_table_id).jqGrid({
                    url: "/@childentity/Index?configurationId=" + row_id,
                    datatype: "json",
                    colNames: ["物料名称", "物料编号", "物料名称", "数量", "单位", "备注"],
                    colModel: [
                    $.jgridx.customAutoCol("ProductId", "/configurationitem/get", "/product/get?id="),
                    $.extend($.jgridx.strCol("Product.Number"), { editable : false }),
                    $.extend($.jgridx.strCol("Product.Name"), { editable : false }),
                    $.jgridx.intCol("Count"),
                    { name: 'Product.Unit', index: 'Product.Unit', width: 80, search: false },
                    {
                        name: "Remark",
                        index: "Remark",
                        width: 280,
                        editable: true,
                        edittype: "textarea",
                        search: false
                    }],

                    rowNum: 10,
                    pager: pager_id,
                    sortname: '@(childentity)Id',
                    sortorder: "asc",
                    height: '100%'
                });
                jQuery("#" + subgrid_table_id).jqGrid('navGrid', "#" + pager_id,
                {
                    edit: true,
                    add: true,
                    del: true
                },
                {
                    url: "/@childentity/Edit"
                },
                {
                    url: "/@childentity/Add?configurationId=" + row_id
                },
                {
                    url: "/@childentity/Delete/"
                }, {}, {});
            },
            loadComplete: function (data) {

                if (!data.success)
                    $(this).jqGrid("clearGridData", true);
            }
        });
        $("#@list").jqGrid('navGrid', '#@pager',
        {
            edit: true,
            add: true,
            search: true,
            del: true,
            refresh: true
        },
        {
            url: "/@entity/edit/"
        },
        {
            url: "/@entity/add/"
        },
        {
            url: "/@entity/delete/"
        }, {}, {});
    });
</script>